package com.xxxx.server.controller;


import com.xxxx.server.pojo.*;
import com.xxxx.server.service.IEmployeeEcService;
import com.xxxx.server.service.IEmployeeTrainService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhanglishen
 * @since 2020-11-14
 */
@RestController
@RequestMapping("/employee-train")
public class EmployeeTrainController {

    @Autowired
    private IEmployeeTrainService employeeTrainService;

    @ApiOperation(value = "添加培训记录")
    @PostMapping("/add")
    public RespBean add(@RequestBody EmployeeTrain employeeTrain){
        if (employeeTrainService.save(employeeTrain)){
            return RespBean.success("培训添加成功");
        }
        return RespBean.error("培训添加失败");
    }

    /**
     * 查询培训记录
     */
    @ApiOperation(value = "查询培训记录")
    @GetMapping("/getTrainList")
    public RespPageBean getTrainList(@RequestParam(defaultValue = "1") Integer currentPage, @RequestParam(defaultValue = "10") Integer size,
                                          EmployeeTrainBean employeeTrainBean){
        return employeeTrainService.getTrainList(currentPage,size,employeeTrainBean);
    }

    @ApiOperation(value = "删除培训记录")
    @DeleteMapping("/delete/{id}")
    public RespBean delete(@PathVariable Integer id){
        if (employeeTrainService.removeById(id)){
            return RespBean.success("删除成功");
        }
        return RespBean.error("删除失败");
    }

}
